package com.sunplus.common.core.ossstorage.aliyunstorage;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.OSSObject;
import com.sunplus.common.core.ossstorage.inteface.IStorageFile;
import com.sunplus.common.utils.file.FileUtils;

import java.io.InputStream;
import java.util.Date;
import java.util.stream.Stream;

/**
 * @author shaoqi
 * @ClassName aliyunOssFile
 * @Description 阿里云文件实现类
 * @date 2021/2/9 0009
 */

public class AliyunOssFile implements IStorageFile {


    private OSS ossClient;

    private OSSObject oss;

    private String rootPath;

    public AliyunOssFile(OSS ossclient, OSSObject oss, String rootpath) {
        this.ossClient = ossclient;
        this.oss = oss;
        this.rootPath = rootpath;
    }

    @Override
    public String getPath() {
        return oss.getKey();
    }

    @Override
    public String getName() {
        return AliyunOssUtil.Util.getEntityName(oss.getKey());
    }

    @Override
    public long getSize() {
        return oss.getObjectMetadata().getContentLength();
    }

    @Override
    public Date getLastUpdated() {
        return oss.getObjectMetadata().getLastModified();
    }

    @Override
    public String getFileType() {
        return FileUtils.getFileExtension(oss.getKey());
    }

    @Override
    public InputStream openRead() {
        return oss.getObjectContent();
    }

    @Override
    public InputStream openWrite() {
        return oss.getObjectContent();
    }
}
